function timeZero(n) {
  return n < 10 ? "0" + n : n;
}
template.defaults.imports.dateFormate = function (pub_date) {
  console.log(pub_date);
  let date = new Date(pub_date);
  let year = date.getFullYear();
  let mouth = date.getMonth() + 1;
  let day = date.getDate();
  let h = date.getHours();
  let min = date.getMinutes();
  let sec = date.getSeconds();
  return `${year}-${timeZero(mouth)}-${timeZero(day)} ${timeZero(h)}:${timeZero(
    min
  )}:${timeZero(sec)}`;
};

template.defaults.imports.dateMouth = function (pub_date) {
  console.log(pub_date);
  let date = new Date(pub_date);
  let mouth = date.getMonth() + 1;
  return `${timeZero(mouth)}`;
};
function more(size) {
  $.ajax({
    url: "http://124.223.14.236:8900/api/articles",
    data: {
      pagenum: 1,
      pagesize: size,
    },
    success: function (res) {
      console.log(res);
      console.log(res.total);
      $("#kr_news_list").append(template("template", res));
      if (size === res.total) {
        $(".kr_more a").off("click").html("没有更多了");
      }
    },
  });
}
let size = 4;
more(size);
let n = 2;
$(".kr_more a").on("click", function () {
  $("#kr_news_list").html("");
  let size = 4;
  size = 4 * n;
  more(size);
  n++;
});

// $(window).on("scroll", function () {
//   if ($(window).scrollTop() == $(document).height() - $(window).height()) {
//     console.log(1, $(document).height(), $(window).height());
//     let n = 2;
//     $("#kr_news_list").html("");
//     let size = 4;

//     size = 4 * n;
//     more(size);
//     n++;
//     if (n === 5) {
//       $(".kr_more a").off("click").html("没有更多了");
//     }
//   }
// });
